<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const reles = [
            {
                "id": 1,
                "name": "系统管理员",
                "createdAt": null,
                "updatedAt": null,
                "permissionIds": null
            }
        ]
        const list = [
            {
                "id": 14,
                "name": "信则1",
                "createdAt": 1722913368,
                "updatedAt": 1722928489,
                "permissionIds": null
            },
            {
                "id": 12,
                "name": "task",
                "createdAt": 1722842905,
                "updatedAt": 1722842905,
                "permissionIds": null
            },
            {
                "id": 3,
                "name": "HELLO",
                "createdAt": 1722672285,
                "updatedAt": 1722672285,
                "permissionIds": null
            },
            {
                "id": 1,
                "name": "系统管理员",
                "createdAt": 1719625408,
                "updatedAt": 1722928444,
                "permissionIds": null
            }
        ]
        const roleIds = list.filter(item => reles.some(key => key.id === item.id));
        function removeEmptyQueryParams(url) {
            const [path, queryParams] = url.split('?'); // 分割路径和查询参数

            // 如果查询参数部分为空，则直接返回原始路径
            if (!queryParams) {
                return url;
            }

            const queryParts = queryParams.split('&'); // 分割查询参数为键值对数组

            // 使用reduce过滤掉值为空的参数，并构建新的查询字符串
            const newQueryStr = queryParts.reduce((acc, part) => {
                const [key, value] = part.split('=');
                if (value) {
                    acc.push(`${key}=${value}`);
                }
                return acc;
            }, []);

            // 如果过滤后的查询字符串为空，则返回路径部分
            const newStr = newQueryStr.length > 0 ? `${path}?${newQueryStr.join('&')}` : path;

            return newStr;
        }

        // 测试代码
        const str1 = '/vstream/user/user/page?pageNo=1&pageSize=10&username=';
        const str2 = '/vstream/user/user/page?111111';
        const str3 = '/vstream/user/user/page?'; // 没有参数的查询字符串

        console.log(removeEmptyQueryParams(str1)); // 输出: /vstream/user/user/page?pageNo=1&pageSize=10
        console.log(removeEmptyQueryParams(str2)); // 输出: /vstream/user/user/page?111111
        console.log(removeEmptyQueryParams(str3)); // 输出: /vstream/user/user/page

    </script>
</body>

</html>